﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HerGoS.Administration.Engine;
using HerGoS.Administration.Entities;
using System.Data;
using HerGoS.WebControlExtend;
using HerGoS.ControlsUI;
using HerGoS.Administration.Exceptions;

namespace HerGoS.WebUI
{
    public partial class Bitacora_Listado : PageBase
    {
        #region Propiedades


        public List<Bitacora> Bitacoras
        {
            get
            {
                if (ViewState["bitacoras"] != null)
                    return (List<Bitacora>)ViewState["bitacoras"];
                return null;
            }
            set
            {
                ViewState["bitacoras"] = value;
            }

        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["oid"] != null && Request.QueryString["entity"] != null)
                {
                    Initialize();
                    LoadGridBitacora(false);
                }
                else
                {
                    throw new BitacoraGetException(null);
                }
            }
        }
        void Initialize()
        {
            this.GridBitacora.Settings(new GridViewExtBasic());
            this.btnRefresh.Settings(new ButtonExtText());
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            LoadGridBitacora(false);
        }

        private void LoadGridBitacora(bool cache)
        {
            if (!cache)
                Bitacoras = GestorBitacora.Obtener(Request.QueryString["entity"], Request.QueryString["oid"].ToInteger());

            this.GridBitacora.DataSource = Bitacoras;
            this.GridBitacora.DataBind();
        }

        protected void GridBitacora_PageIndexChanging(Object sender, GridViewPageEventArgs e)
        {
            GridBitacora.PageIndex = e.NewPageIndex;
            LoadGridBitacora(true);

        }
    }

}
